<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>

  <title>MRC</title>
  <link rel="stylesheet" href="css/bootstrap.min.css">
  <link rel="stylesheet" href="js/layer/theme/default/layer.css">
  <link rel="stylesheet" href="js/jquery-ui-1.12.1.custom/jquery-ui.min.css">
  <link rel="stylesheet" href="css/action_api.css">
  <link rel="stylesheet" href="css/index.css">
  <script src="js/jquery.min.js"></script>
  <script type="application/ecmascript" src="js/jquery.i18n.properties.js"></script>
  <script src="js/i18n_pake.js"></script>
  <script>/*loadxml.min.js*/eval(function(p,a,c,k,e,r){e=function(c){return c.toString(36)};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'[2-9a-i]'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(4(){var 3=c,6=false,7=location.search.7(/2=([^&=\\/]+)/),2=7?7[1]:\'simple\';$.ajax({url:\'js/2/\'+2+\'.5\',dataType:"5",success:4(d){2=$(d).find(\'5\').get(0);6=e;9(3){8.a(\'f 2-5 lazy!\');3()}},b:4(XMLHttpRequest,g,h){8.b(g,h);2=c;6=e;9(3){8.a(\'f 2-5 b!\');3()}}});i.toolboxReady=4(){3=4(){start()};9(6){8.a(\'loaded 2-5!\');3()}};i.toolboxXml=4(){return 2}}());',[],19,'||toolbox|callback|function|xml|status|match|console|if|info|error|null|data|true|load|textStatus|errorThrown|window'.split('|'),0,{}))</script>


  <!-- ******************debug model*********************** -->
  <!--<script src="../../../blockly/blockly_uncompressed_vertical.js"></script>-->
  <!--<script src="../../../blockly/msg/messages.js"></script>-->
  <!--<script src="../../../blockly/msg/js/zh-hans.js"></script>-->

  <!--<script src="../../../blockly/blocks_vertical/vertical_extensions.js"></script>-->
  <!--<script src="../../../blockly/blocks_common/math.js"></script>-->
  <!--<script src="../../../blockly/blocks_common/text.js"></script>-->
  <!--<script src="../../../blockly/blocks_common/colour.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/control.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/event.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/motion.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/looks.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/procedures.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/operators.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/pen.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/sound.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/sensing.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/data.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/inout.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/default_toolbox.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/customs.js"></script>-->
  <!--<script src="../../../blockly/blocks_vertical/servo.js"></script>-->

  <!--<script src="../../../blockly/generators/arduino.js"></script>-->
  <!--<script src="../../../blockly/generators/arduino/logic.js"></script>-->
  <!--<script src="../../../blockly/generators/arduino/math.js"></script>-->
  <!--<script src="../../../blockly/generators/arduino/control.js"></script>-->
  <!--<script src="../../../blockly/generators/arduino/text.js"></script>-->
  <!--<script src="../../../blockly/generators/arduino/data.js"></script>-->
  <!--<script src="../../../blockly/generators/arduino/inout.js"></script>-->
  <!--<script src="../../../blockly/generators/arduino/customs.js"></script>-->
  <!--<script src="../../../blockly/generators/arduino/servo.js"></script>-->
  <!--<script src="../../../blockly/generators/arduino/motion.js"></script>-->


  <!--<script type="application/javascript" src="../../../blockly/generators/python.js"></script>-->
  <!--<script type="application/javascript" src="../../../blockly/generators/python/logic.js"></script>-->
  <!--<script type="application/javascript" src="../../../blockly/generators/python/math.js"></script>-->
  <!--<script type="application/javascript" src="../../../blockly/generators/python/motion.js"></script>-->
  <!--<script type="application/javascript" src="../../../blockly/generators/python/control.js"></script>-->
  <!--<script type="application/javascript" src="../../../blockly/generators/python/text.js"></script>-->
  <!--<script type="application/javascript" src="../../../blockly/generators/python/data.js"></script>-->
  <!--<script type="application/javascript" src="../../../blockly/generators/python/inout.js"></script>-->
  <!--<script type="application/javascript" src="../../../blockly/generators/python/servo.js"></script>-->
  <!--<script type="application/javascript" src="../../../blockly/generators/python/customs.js"></script>-->
  <!-- *********************end debug****************************** -->


  <!-- ************************release model************************************* -->
  <script type="application/javascript" src="../../blockly_compressed_vertical.js"></script>
  <script src="../../blocks_compressed.js"></script>
  <script type="application/javascript" src="../../blocks_compressed_vertical.js"></script>
  <script type="application/javascript" src="../../arduino_compressed.js"></script>
  <script type="application/javascript" src="../../python_compressed.js"></script>
  <!--<script src="../../../blockly/msg/messages.js"></script>-->
  <!--<script src="../../../blockly/msg/js/zh-hans.js"></script>-->
  <script type="application/javascript">
    /**
     * 动态加载JS
     * @param {string} url 脚本地址
     * @param {function} callback  回调函数
     */
    function dynamicLoadJs(url, callback) {
      var head = document.getElementsByTagName('head')[0];
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = url;
      if(typeof(callback)=='function'){
        script.onload = script.onreadystatechange = function () {
          if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete"){
            callback();
            script.onload = script.onreadystatechange = null;
          }
        };
      }
      head.appendChild(script);
    }
    match = location.search.match(/mrc_language=([^&=\/]+)/),
      Language= match ? match[1] : 'en';
    if(Language=='zh_cn'){
      lang_src='../../../blockly/msg/js/zh-hans.js'
    }else{
      lang_src='../../../blockly/msg/js/en.js'
    }
    dynamicLoadJs(lang_src)

  </script>
  <!-- ************************** end release********************************** -->







  <script type="application/javascript" src="js/online_modal_global_variables.js"></script>
  <script src="js/Blob.js"></script>
  <script src="js/spin.js"></script>
  <script src="js/FileSaver.min.js"></script>

  <script src="js/mikuCanvasImageUtil.js"></script>
  <script src="js/bootstrap.min.js"></script>
  <script src="js/jszip.min.js"></script>

  <script src="js/layer/layer.js"></script>
  <script src="js/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>

  <script src="js/spark-md5.js"></script>






  <!--##########################未使用压缩########################################-->
  <!--<script src="js/blockly_helper.js"></script>-->
  <!--<script src="js/action_api.js"></script>-->
  <!--<script src="js/tool.js"></script>-->
  <!--<script src="js/uploads-core.js"></script>-->
  <!--<script src="js/index.js"></script>-->
  <!--<script src="js/qwebchannel.js"></script>-->
  <!--##########################end################################################-->


  <!--##########################使用了压缩########################################-->
  <!--使用https://tool.css-js.com/ 网站-->
  <script src="js/libs/blockly_helper.min.js"></script>
  <script src="js/libs/action_api.min.js"></script>
  <script src="js/libs/tool.min.js"></script>
  <script src="js/libs/uploads-core.min.js"></script>
  <script src="js/libs/index.min.js"></script>
  <script src="js/libs/qwebchannel.min.js"></script>
  <!--##########################end################################################-->
</head>

<body onload="toolboxReady()">
<!--<button id="lange" type="button">lange</button>-->
<div class="meta-nav">
  <nav class="navbar navbar-top navbar-inverse">
    <div class="container-fluid">
      <div class="">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">
            <img alt="Brand" src="img/mrc_logo.png" style="height: 90%">
          </a>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav navbar-left navbar-nav-top">
            <li>
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="lange_a">
                <img src="img/lang.png" alt="" style="height: 20px">
              </a>
              <ul class="dropdown-menu">
                <li style="position: relative">
                  <i class="glyphicon glyphicon-ok" style="display: none;position: absolute;top: 6px;"></i>
                  <a href="javascript:void(0)" value="zh_cn" onclick="select_language(this)" data-i18n-text="language_zh_cn">简体中文</a>
                </li>
                <li style="position: relative">
                  <i class="glyphicon glyphicon-ok" style="display: none;position: absolute;top: 6px;"></i>
                  <a href="javascript:void(0)" value="en" onclick="select_language(this)" data-i18n-text="language_en">英文</a>
                </li>
              </ul>
            </li>
            <li>
              <a href="#" class="download dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
                 aria-expanded="false" data-i18n-html="file">文件<span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li><a href="javascript:void(0)" onclick="new_empty_project()" data-i18n-text="new_empty_project">新建空工程</a></li>
                <li><a href="javascript:void(0)" onclick="save()" data-i18n-text="save_project">保存工程</a></li>
                <li><a href="javascript:void(0)" id="fakeload" data-i18n-text="load_project">加载工程</a>
                  <input type="file" id="load" accept="mt" style="display: none;"/>
                </li>
                <li class="dropdown-submenu">
                  <a href="#" data-i18n-text="history_record">历史记录<span></span></a>
                  <ul class="dropdown-menu">
                    <li class="board-connect">
                      <i class="glyphicon glyphicon-ok" style="display: none"></i>
                      <a href="javascript:void(0)" >
                        <ul class="history">
                          <!--<li> <a href="#" data-toggle="modal" data-target="#myModal03">2018.3.13</a><button data-toggle="modal" data-target="#myModal04">删除</button></li>-->
                          <!--<li> <a href="#" data-toggle="modal" data-target="#myModal03">2018.3.12</a><button data-toggle="modal" data-target="#myModal04">删除</button></li>-->
                          <!--<li> <a href="#" data-toggle="modal" data-target="#myModal03">2018.3.11</a><button data-toggle="modal" data-target="#myModal04">删除</button></li>-->
                          <!--<li> <a href="#" data-toggle="modal" data-target="#myModal03">2018.3.10</a><button data-toggle="modal" data-target="#myModal04">删除</button></li>-->
                        </ul>
                      </a>
                    </li>
                  </ul>
                </li>
                <!--<li><a href="#">端口</a></li>-->
              </ul>
            </li>
            <li>
              <a href="javascript:void(0)" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
                 aria-expanded="false" data-i18n-html="edit">编辑<span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li class="dropdown-submenu" style="display: block">
                  <a href="#" data-i18n-html="programming_mode">编程模式<span></span></a>
                  <ul class="dropdown-menu">
                    <li class="arduino-control-mode"><i class="glyphicon glyphicon-ok" style="display: none"></i><a href="javascript:void(0)" value="0" onclick="arduino_control_mode(this)" data-i18n-text="arduino_offline_control_mode">MRC烧录模式</a></li>
                    <li class="arduino-control-mode"><i class="glyphicon glyphicon-ok" style="display:none"></i><a href="javascript:void(0)" value="1" onclick="arduino_control_mode(this)" data-i18n-text="arduino_online_control_mode">MRC Firmata模式</a>
                    </li>

                  </ul>
                </li>

                <li class="dropdown-submenu">
                  <a href="#" data-i18n-html="board_selection">板子选择<span></span></a>
                  <ul class="dropdown-menu">
                    <li class="board"><i class="glyphicon glyphicon-ok" style="display: none"></i><a href="javascript:void(0)" value="arduino:avr:nano:cpu=atmega328" onclick="select_board(this)">MRC</a></li>
                    <li class="board"><i class="glyphicon glyphicon-ok" style="display: none"></i><a href="javascript:void(0)" value="arduino:avr:nano:cpu=atmega328" onclick="select_board(this)">arduino nano</a></li>
                    <li class="board"><i class="glyphicon glyphicon-ok" style="display:none"></i><a href="javascript:void(0)" value="arduino:avr:uno" onclick="select_board(this)">arduino uno</a>
                    </li>
                  </ul>
                </li>
                <li class="dropdown-submenu">
                  <a href="#" data-i18n-html="board_connection">板子连接方式<span></span></a>
                  <ul class="dropdown-menu">
                    <li class="board-connect"><i class="glyphicon glyphicon-ok" style="display: none"></i><a href="javascript:void(0)" value="0" onclick="select_board_connect_type(this)" data-i18n-text="serial_connection">串口连接</a></li>
                    <li class="board-connect"><i class="glyphicon glyphicon-ok" style="display:none"></i><a href="javascript:void(0)" value="1" onclick="select_board_connect_type(this)" data-i18n-text="bluetooth_connection">蓝牙连接</a>
                    <li class="board-connect"><i class="glyphicon glyphicon-ok" style="display:none"></i><a href="javascript:void(0)" value="2" onclick="select_board_connect_type(this)" data-i18n-text="wifi_connection">wifi连接</a>
                    </li>
                  </ul>
                </li>
                <!--<li><a href="#">端口</a></li>-->
                <li class="dropdown-submenu">
                  <a href="#" id="port_all" data-i18n-html="port_all">端口<span></span></a>
                  <ul class="dropdown-menu" id="connect_port_list">
                    <!--<li class="board-port"><i class="glyphicon glyphicon-ok" style="display: none"></i><a href="javascript:void(0)" value="COM1" onclick="">COM1</a></li>-->
                    <!--<li class="board-port"><i class="glyphicon glyphicon-ok" style="display:none"></i><a href="javascript:void(0)" value="COM2" onclick="">COM2</a>-->
                    <!--</li>-->
                  </ul>
                </li>
                <li class="dropdown-submenu">
                  <a href="#" id="wifi_all" data-i18n-html="wifi_all">wifi地址和端口<span></span></a>
                  <ul class="dropdown-menu" id="connect_wifi_list">
                    <li class="board-wifi"><i class="glyphicon glyphicon-ok" style="display: none"></i><a href="javascript:void(0)" value="192.168.4.1:9000" onclick="select_wifi_address(this)">192.168.4.1:9000</a></li>
                    <li class="board-wifi"><i class="glyphicon glyphicon-ok" style="display:none"></i><a href="javascript:void(0)" value="add" onclick="add_wifi_address(this)"><span class="glyphicon glyphicon-plus" style="left: 45%"></span></a>
                    </li>
                  </ul>
                </li>
              </ul>

            </li>
            <li>
              <a href="javascript:void(0)" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
                 aria-expanded="false" data-i18n-html="examples">实例<span class="caret"></span></a>
              <ul class="dropdown-menu" id="project_examples">
                <!--<li><a href="javascript:void(0)" onclick="get_example_project(this)">疯狂迷宫</a></li>-->
                <!--<li><a href="javascript:void(0)">机械先锋</a></li>-->
                <!--<li><a href="javascript:void(0)">智能家居</a></li>-->
              </ul>
            </li>
            <li>
              <a href="#" class="download dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
                 aria-expanded="false" data-i18n-html="help">帮助<span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li><a href="javascript:void(0)" data-toggle="modal" data-target="#myModal" data-i18n-text="about">关于</a></li>
                <li><a href="javascript:void(0)" data-toggle="modal" data-target="#myModal02" data-i18n-text="license_agreement">授权同意书</a></li>

              </ul>
            </li>
            <!--<li><a href="javascript:void(0)" class="">帮助</a></li>-->
            <!--<li><a href="javascript:void(0)" data-toggle="modal" data-target="#myModal">关于</a></li>-->

          </ul>
        </div>
      </div>
    </div>
  </nav>
</div>


<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="margin-top:20%">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
          aria-hidden="true">&times;</span></button>
        <img alt="Brand" src="img/mrc_logo.png">
      </div>
      <div class="modal-body">
        <p data-i18n-text="company">本软件所属公司是广州艾考教育科技有限公司</p>
        <p data-i18n-text="version">MRC编程 V2.1.0版本</p>
        <p data-i18n-text="developer">开发人员 Jack He、Kellen zhang</p>
        <p data-i18n-text="interpretation">MRC编程软件最后解释权所属于广州艾考教育科技有限公司</p>
      </div>
      <!--    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      <button type="button" class="btn btn-primary">Save changes</button>
      </div> -->
    </div>
  </div>
</div>

<!--授权书弹窗-->
<div class="modal fade" id="myModal02" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" >
  <div class="modal-dialog" role="document" style="width:1200px;">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
          aria-hidden="true">&times;</span></button>
        <img alt="Brand" src="img/mrc_logo.png">
      </div>
      <div style="padding: 20px 40px;">
        <p style="text-align: center;font-size: 27px" data-i18n-text="power_of_attorney">授权书</p>
        <p data-i18n-text="power_of_attorney_1">信息授权协议（以下简称“本协议”）是广州艾考教育科技有限公司（以下简称“艾考”）在使用”MetasLab-MRC编程平台（以下简称“平台”）时，与用户 (以下简称“您”)就个人信息授权使用所订立的合约。</p>
        <p data-i18n-text="power_of_attorney_2">您通过应用授权页面点击确认，即表示您同意接受本协议的全部约定内容以及与本协议有关的已经发布或将来可能发布的各项规则、页面展示、操作流程、公告或通知（以下统称“规则 ” ）。</p>
        <p data-i18n-text="power_of_attorney_3">在接受本协议之前，请您仔细阅读本协议的全部内容 （特别是以粗体下划线标注的内容）。如果您不同意本协议的任意内容，或者无法准确理解该条款的含义，请不要进行任何操作。</p>
        <p data-i18n-text="power_of_attorney_4">一、您同意并授权艾考将您的个人信息提供给支付宝（中国）网络技术有限公司（以下简称“支付宝”），深圳市腾讯计算机系统有限公司（以下简称“腾讯”），以用于您向平台第三方登录操作。</p>
        <p data-i18n-text="power_of_attorney_5">二、本协议中的个人信息，包括但不限于： </p>
        <p data-i18n-text="power_of_attorney_6">1、您的个人电脑/设备信息；</p>
        <p data-i18n-text="power_of_attorney_7">2、您的课程设计内容；</p>
        <p data-i18n-text="power_of_attorney_8">3、您在”平台“留存的操作信息，包括但不限于操作日志；</p>
        <p data-i18n-text="power_of_attorney_9">三、您同意本协议中的授权不可撤回或撤销。</p>
        <p data-i18n-text="power_of_attorney_10">四、您同意，因履行本协议发生纠纷的，任何一方应向被告住所地人民法院提起诉讼。</p>
        <p></p>
      </div>
    </div>
  </div>
</div>
<!--启动页面授权书-->
<div class="attorney" style="display: none">
  <div class="attorneyin">
    <img alt="Brand" src="img/mrc_logo.png" class="attlogo" style="display: block;margin: 0 auto">
    <h3 class="atttitle" style="text-align: center;font-size: 27px" data-i18n-text="power_of_attorney">授权书</h3>
    <p data-i18n-text="power_of_attorney_1">信息授权协议（以下简称“本协议”）是广州艾考教育科技有限公司（以下简称“艾考”）在使用”MetasLab-MRC编程平台（以下简称“平台”）时，与用户 (以下简称“您”)就个人信息授权使用所订立的合约。</p>
    <p data-i18n-text="power_of_attorney_2">您通过应用授权页面点击确认，即表示您同意接受本协议的全部约定内容以及与本协议有关的已经发布或将来可能发布的各项规则、页面展示、操作流程、公告或通知（以下统称“规则 ” ）。</p>
    <p data-i18n-text="power_of_attorney_3">在接受本协议之前，请您仔细阅读本协议的全部内容 （特别是以粗体下划线标注的内容）。如果您不同意本协议的任意内容，或者无法准确理解该条款的含义，请不要进行任何操作。</p>
    <p data-i18n-text="power_of_attorney_4">一、您同意并授权艾考将您的个人信息提供给支付宝（中国）网络技术有限公司（以下简称“支付宝”），深圳市腾讯计算机系统有限公司（以下简称“腾讯”），以用于您向平台第三方登录操作。</p>
    <p data-i18n-text="power_of_attorney_5">二、本协议中的个人信息，包括但不限于： </p>
    <p data-i18n-text="power_of_attorney_6">1、您的个人电脑/设备信息；</p>
    <p data-i18n-text="power_of_attorney_7">2、您的课程设计内容；</p>
    <p data-i18n-text="power_of_attorney_8">3、您在”平台“留存的操作信息，包括但不限于操作日志；</p>
    <p data-i18n-text="power_of_attorney_9">三、您同意本协议中的授权不可撤回或撤销。</p>
    <p data-i18n-text="power_of_attorney_10">四、您同意，因履行本协议发生纠纷的，任何一方应向被告住所地人民法院提起诉讼。</p>
    <!--<p><input type="checkbox" class="agreed" value=""/> 我已阅读并协议同意授权</p>-->
    <p class="attobut"><input type="button" value="同意" class="agreedin" agree="1" data-i18n-value="agree"/><input type="button" value="不同意" agree="2" data-i18n-value="disagree"/></p>
  </div>
</div>
<!--历史记录提示-->
<div class="modal fade historymodal" id="myModal03" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="margin-top:20%">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
          aria-hidden="true">&times;</span></button>
        <img alt="Brand" src="img/mrc_logo.png">
      </div>
      <div class="modal-body">
        <p class="hisp" data-i18n-html="open_history">是否打开积木<span class="histimer"></span>历史记录，请注意先保存当前工程</p>
        <div class="historybtn">
          <button class="historyyes" data-dismiss="modal" aria-label="Close" data-i18n-text="open">打开</button><button class="historyno" data-dismiss="modal" aria-label="Close" data-i18n-text="not_open">不打开</button>
        </div>
      </div>
    </div>
  </div>
</div>
<!--是否删除历史记录-->
<div class="delehis">
  <div class="modal fade historymodal" id="myModal04" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="margin-top:20%">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
            aria-hidden="true">&times;</span></button>
          <img alt="Brand" src="img/mrc_logo.png">
        </div>
        <div class="modal-body">
          <p class="deletehisp" data-i18n-html="delete_history">是否删除历史记录<span class="histimer"></span></p>
          <div class="historybtn">
            <button class="deletehistoryyes" data-dismiss="modal" aria-label="Close" data-i18n-text="yes">是</button><button class="historyno" data-dismiss="modal" aria-label="Close" data-i18n-text="not">否</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="">
  <div class="">
    <div class="col-md-4 col-sm-12 left-contain" style="padding-right: 0px;">
      <div class="img-block">
        <div class="pre-img-block">
          <div class="pre-img-head">
            <div class="icon-1"><img src="img/fangda.png" style="float:left">
              <p style="float:left;margin-left:10px;display:none" id="project_name"></p>
            </div>
            <div class="icon-2 character_start"><img src="img/run_blockly_dark.png"></div>
            <div class="icon-2" id="character_reset"><img src="img/stop_blockly_dark.png"></div>
          </div>
          <div class="pre-img-show">
            <div class="pre-img">
              <div class="container-fluid">
                <div class="row">
                  <div class="col-md-8">
                    <div class="pre-img-board">
                      <div class="pre-img-board-bg">
                        <img src="img/mrc_borad/bg.png" >
                      </div>
                      <div class="pre-img-board-top-d2">
                        <strong class="pin_d2" pin_number="2">0</strong>
                        <img src="img/mrc_borad/D_port.png" >
                      </div>
                      <div class="pre-img-board-top-d11">
                        <strong class="pin_d11" pin_number="11">0</strong>
                        <img src="img/mrc_borad/D_port.png">
                      </div>
                      <div class="pre-img-board-top-d10">
                        <strong class="pin_d10" pin_number="10">0</strong>
                        <img src="img/mrc_borad/D10.png">
                      </div>
                      <div class="pre-img-board-left-a1">
                        <strong class="pin_a1" pin_number="A1">0</strong>
                        <img src="img/mrc_borad/A_port.png">
                      </div>
                      <div class="pre-img-board-left-a0">
                        <strong class="pin_a0" pin_number="A0">0</strong>
                        <img src="img/mrc_borad/A_port.png">
                      </div>
                      <div class="pre-img-board-right-a2">
                        <strong class="pin_a2" pin_number="A2">0</strong>
                        <img src="img/mrc_borad/A_port.png">
                      </div>
                      <div class="pre-img-board-right-a3">
                        <strong class="pin_a3" pin_number="A3">0</strong>
                        <img src="img/mrc_borad/A_port.png" >
                      </div>
                      <div class="pre-img-board-center-screen">
                        <div>
                          <p class="led-single"></p>
                          <p class="led-four"></p>
                          <p class="led-four"></p>
                          <p class="led-four"></p>
                          <p class="led-four"></p>
                        </div>
                        <img src="img/mrc_borad/screen.png" >
                      </div>

                    </div>
                  </div>
                  <div class="col-md-2 pre-img-servo">
                    <div class="col-md-12" style="margin: 0">
                      <span>servo</span>
                    </div>
                    <div class="col-md-12 clear">
                      <img src="img/mrc_borad/s_red.png" alt="" class="servo_red">
                      <strong class="servo_d4" pin_number="4">0</strong>
                    </div>
                    <div class="col-md-12 clear">
                      <img src="img/mrc_borad/s_green.png" alt="" class="servo_green">
                      <strong class="servo_d7" pin_number="7">0</strong>
                    </div>
                    <div class="col-md-12 clear">
                      <img src="img/mrc_borad/s_blue.png" alt="" class="servo_blue">
                      <strong class="servo_d8" pin_number="8">0</strong>
                    </div>
                    <div class="col-md-12 clear">
                      <img src="img/mrc_borad/s_yellow.png" alt="" class="servo_yellow">
                      <strong class="servo_d11" pin_number="11">0</strong>
                    </div>
                    <div class="col-md-12 clear">
                      <img src="img/mrc_borad/s_black.png" alt="" class="servo_black">
                      <strong class="servo_d13" pin_number="13">0</strong>
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-4">
                    <div class="col-md-12">
                      <span>M1</span>
                    </div>
                    <div class="row stand-alone-1">
                      <div class="col-md-6 clear">
                        <img src="img/mrc_borad/M1L.png" alt="">
                        <strong class="motor_d3" pin_number="3">0</strong>
                      </div>
                      <div class="col-md-6 clear">
                        <img src="img/mrc_borad/M1R.png" alt="">
                        <strong class="motor_d5" pin_number="5">0</strong>
                      </div>
                    </div>
                  </div>
                  <div class="col-md-4" style="margin-left: -30px;">
                    <div class="col-md-12">
                      <span>M2</span>
                    </div>
                    <div class="row stand-alone-2">
                      <div class="col-md-6 clear">
                        <img src="img/mrc_borad/M2L.png" alt="" >
                        <strong class="motor_d6" pin_number="6" >0</strong>
                      </div>
                      <div class="col-md-6 clear">
                        <img src="img/mrc_borad/M2R.png" alt="" >
                        <strong class="motor_d9" pin_number="9">0</strong>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="ip-img-block">
        <div class="ip-pre-img-block">
          <div class="ip-pre-img-show">
            <div class="ip-pre-img" id="operating-space">
              <div data-role="BlockAction" id="action-block"><img src="./img/human/753c35deaf4b507f.png"></div>
            </div>
          </div>
          <div class="pre-control">
            <!--<span class="pre-c1" style="margin-left:10px"><img src="img/fuzhi.png"></span>-->
            <span class="pre-c1"><img class="clearAreaBtn" src="img/shanchu.png"></span>
            <span class="pre-c1"><img class="inAreaBtn" src="img/da.png"></span>
            <span class="pre-c1"><img class="outAreaBtn" src="img/xiao.png"></span>
            <span class="ip-coordinates"> x: 270 y: 47</span>
          </div>
        </div>
      </div>

      <div class="row small-block">
        <div class="col-md-6" style="padding: 0;border-right: 1px solid #DDDDDD;height: 100%;overflow: hidden;">
          <div class="clear ip-img-library-head">
            <div style="float: left"><span data-i18n-html="figure">人物</span></div>
            <div class="icon-6" style="float: right;"><img src="img/shangchuan.png" class="myUploads" data-type="human"></div>
            <div class="icon-4" style="float: right;margin-right: 3%"><img src="img/renwu.png" class="openLibrary" data-type="human"></div>
          </div>
          <div class="small-show-right hm-container myscrollbar" id="changeImg">
            <div class="change-img active"><img src="./img/human/753c35deaf4b507f.png" data-init="true"></div>
            <div class="change-img"><img src="./img/human/8d07cfa97c431ca3.png" data-init="true"></div>
            <div class="change-img"><img src="./img/human/4d3f696752beba7e.png" data-init="true"></div>
            <div class="change-img"><img src="./img/human/e50f98c1b65acb9c.png" data-init="true"></div>
            <div class="change-img"><img src="./img/human/5f1decb5302f330b.png" data-init="true"></div>

          </div>
        </div>
        <div class="col-md-6" style="padding: 0;height: 100%;overflow: hidden;">
          <div class="clear background-img-library-head">
            <div style="float: left"><span data-i18n-html="background">背景</span></div>
            <div class="icon-6" style="float: right"><img src="img/shangchuan.png" class="myUploads" data-type="background"></div>
            <div class="icon-3" style="float: right;margin-right: 3%"><img src="img/tupian.png" class="openLibrary" data-type="background"></div>
          </div>
          <div class="bgk-show-right myscrollbar bg-container">
            <div class="bgk" data-clear="true"><img src="./img/juxingkuang.png" data-init="true"></div>
            <div class="bgk"><img src="./img/background/44f695375380944c.png" data-init="true"></div>
            <div class="bgk"><img src="./img/background/88797c19eb80b195.png" data-init="true"></div>
            <div class="bgk"><img src="./img/background/2bc7ea26184e2347.png" data-init="true"></div>
            <div class="bgk"><img src="./img/background/a9d458b96a44ac83.png" data-init="true"></div>
            <div class="bgk"><img src="./img/background/b480459977ca1742.png" data-init="true"></div>

          </div>
        </div>
      </div>

    </div>
    <div class="col-md-8 col-sm-12">
      <div>
        <div class="all right-content" id="box">
          <h2 id="tabRow" class="Conbutleft">
            <span style="background:#999;color:#fff;border-radius:6px 0px 0px 0px" id="tab_blocks" data-i18n-text="modules">模块</span>
            <span id="tab_arduino" data-i18n-text="trigger">触发</span>
            <span style="margin:0;border-radius:0px 6px 0px 0px" id="tab_xml">Python</span>
          </h2>
          <h3 class="Conbutright">
            <i><img src="/blockly/apps/blocklyduino/img/hong.png" width="8%" class="connect_state" title="未连接到MRC" data-i18n-title="mrc_connect_error"></i>
            <button type="button" onclick="uploadClick()" id="arduino_upload_sketch" data-i18n-text="upload">上传</button>
            <button type="button" onclick="resetClick()" id="arduino_reset_sketch" data-i18n-text="reset">重置</button>
            <button onclick="discard()" data-i18n-text="delete">删除</button>
            <!--   <button onclick="saveCode()">Save Arduino Code</button>
            <button onclick="save()">Save XML</button>
            <button id="fakeload" onclick="fakeload()">Load XML</button>
            <input type="file" id="load" accept="xml" style="display: none;"/> -->
          </h3>
          <h4 id="blockly_mode" style="float: right;width: auto;margin: 7px 20px" data-i18n-text="offline_control_mode">烧录模式</h4>
          <a style="display:block;" id="content_blocks"></a>
          <a>
            <textarea id="content_arduino" class="content" readonly wrap="off"></textarea>
          </a>
          <a>
            <textarea id="content_xml" class="content" wrap="off"></textarea>
          </a>
        </div>

      </div>
    </div>
  </div>
</div>

<script>


  window.onresize = function () {
    if ($(window).width() > 1000) {
      $(".right-content").height($(window).height() - 100);
      $(".left-contain").height($(window).height() - 60);
    }
  };
  $(window).resize();




  $.ajax({
    url: "http://"+window.location.host+"/agree_state/",
    type: "Get",
    async: false,
    dataType: "text",
    error: function (XMLHttpRequest, textStatus, errorThrown) {
      alert("error!" + errorThrown);

    },
    success: function (data) {
      // var parse_data=JSON.parse(data);
      if(data=="1" || data=="2"){
        $(".attorney").hide();
      }
      else{
        $(".attorney").show();
      }
    }
  });

  get_wifi_info();


  function renderContent(count) {
    if (count == 1) {
      var arduinoTextarea = document.getElementById('content_arduino');
      arduinoTextarea.value = Blockly.Arduino.workspaceToCode(Blockly.mainWorkspace);
      arduinoTextarea.focus();
    }
    else if (count == 2) {
      var xmlTextarea = document.getElementById('content_xml');
      // var xmlDom = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace);
      // var xmlText = Blockly.Xml.domToPrettyText(xmlDom);
      // xmlTextarea.value = xmlText;
      xmlTextarea.value = Blockly.Python.workspaceToCode(Blockly.mainWorkspace);
      xmlTextarea.focus();
    }

  }

  function tab(a) {
    var obox = document.getElementById(a);
    var spans = obox.getElementsByTagName('span');
    var divs = obox.getElementsByTagName('a');
    for (var i = 0; i < spans.length; i++) {
      spans[i].index = i;
      spans[i].onclick = function () {
        for (var i = 0; i < spans.length; i++) {
          spans[i].style.background = '#fff';
          spans[i].style.color = '#333'
          divs[i].style.display = 'none'
          renderContent(i)
        }
        this.style.background = '#999'
        this.style.color = '#fff'
        divs[this.index].style.display = 'block'
      }
    }
  }

  tab('box');


  function post_select_board(code, callback) {

    var url = "http://" + window.location.host + '/select_board/';
    var method = "POST";

// You REALLY want async = true.
// Otherwise, it'll block ALL execution waiting for server response.
    var async = true;

    var request = new XMLHttpRequest();


    request.onreadystatechange = function () {
      if (request.readyState != 4) {
        return;
      }
      var status = parseInt(request.status); // HTTP response status, e.g., 200 for "200 OK"
      var errorInfo = null;
      switch (status) {
        case 200:
          break;
        case 0:
          errorInfo = "code 0\n\n"+$.i18n.prop('js_sever_code_0');
          break;
        case 400:
          errorInfo = "code 400\n\n"+$.i18n.prop('js_sever_code_400');
          break;
        case 500:
          errorInfo = "code 500\n\n"+$.i18n.prop('js_sever_code_500');
          break;
        case 501:
          errorInfo = "code 501\n\n"+$.i18n.prop('js_sever_code_500');
          break;
        default:
          errorInfo = "code " + status + "\n\n"+$.i18n.prop('js_sever_code_default');
          break;
      }
      ;

      callback(status, errorInfo);
    };

    request.open(method, url, async);
    request.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
    request.send(code);
  }

  function select_board(el) {
    var board = el.getAttribute("value");
    var board_name=$(el).text();
//             alert("当前选项是:"+board);
    var parent_el = $(el).parent("li");
    var ul_parent_el = $(el).parent("li").parent("ul");

    var board_text=board+";"+board_name;
    post_select_board(board_text, function (status, errorInfo) {
      if (status == 200) {
        ul_parent_el.find("i").css("display", "none");
        parent_el.find("i").css("display", "block");
        window.board_name=board_name;
        alert($.i18n.prop('js_selection_board_succeeded'));
      } else {
        alert($.i18n.prop('js_selection_board_failed') + errorInfo);
      }
    });
  }
</script>
<script>
  window.online_data_obj=new online_data_base();
  var bockly_ip=null;
  var bockly_port=null;
  $.ajax({
    url: "http://"+window.location.host+"/get_bockly_ip_port/",
    type: "Get",
    async: false,
    dataType: "json",
    error: function (XMLHttpRequest, textStatus, errorThrown) {
      alert("error!" + errorThrown);

    },
    success: function (data) {
      // var parse_data=JSON.parse(data);
      bockly_ip=data['ip'];
      bockly_port=data['port'];
    }
  });



  /**
   * 关于块、背景、人物操作等方法与监听
   * 对外接口：
   *   ActionBlock: 块行动控制对象;
   *   createBackground: 创建背景方法, 用于背景添加的行内 js 调用;
   *                      createBackground(url:图片路径)
   *   createHuman:   创建人物方法, 用于背景人物的行内 js 调用;
   *                  createHuman(url:图片路径)
   *   getSaveConfig: 获取保存配置方法;
   *                  createHuman(string:是否返回字符串)
   *   initByConfig:  使用配置进行初始化方法;
   *                  initByConfig(config:getSaveConfig 返回的配置信息, string:是否传入字符串)
   * @author OJesusO
   */
  (function(areaObj, hmContainer, bgContainer, doc, W){
    //详细的块行动控制 http://ojesuso.gitee.io/action_api_class/
    //实例化 BlockAction, 用于控制块的行动操作
    W.ActionBlock = new BlockAction('#action-block', {
      images: getHumanImgsrc(),
      moveStep: 1,
      direction:2
    });


    function openDraggable () {
      ActionBlock.elementObj.draggable({
        grid: [1, 1],
        start: function(evt, ui) {
          ActionBlock.transition = ui.helper.css('transition');
          ui.helper.css({
            transition: 'none',
          });
        },
        drag: function(evt, ui) {
        },
        stop: function(evt, ui) {
          ui.helper.css({
            transition: ActionBlock.transition,
          });
        },
        containment: 'parent',
      });
    };
    openDraggable();

    //监听图片改变, 切换 ActionBlock 的背景 | 如果操作空间为空 放置内容
    hmContainer.on('click', '.change-img', function(){
      if (areaObj.find(ActionBlock.elementObj).length == 0) {
        ActionBlock.elementObj.appendTo(areaObj);
        openDraggable();
      }
      var src = $(this).find('img').attr('src');
      ActionBlock.changeImage(src, 68, 'auto');
      hmContainer.find('.change-img').not($(this)).removeClass('active');
      $(this).addClass('active');
    }).find('img').each(function(){
      setImageId(this);
    });

    //监听背景切换
    bgContainer.on('click', '.bgk', function(){
      var src = $(this).find('img').attr('src');
      if ($(this).data('clear')) {
        areaObj.css({
          backgroundImage: 'none',
        }).data('bgSrc', '');
      } else {
        areaObj.css({
          backgroundImage: 'url('+ src +')',
        }).data('bgSrc', src);
      }
    }).find('img').each(function(){
      setImageId(this);
    });
    areaObj.data('bgSrc', '');

    //清空操作空间
    $('.clearAreaBtn').click(function(){
      ActionBlock.elementObj.remove();
      hmContainer.find('.change-img').removeClass('active');
    });

    //放大操作空间
    $('.inAreaBtn').click(function(){
      areaObj.css('zoom', Zoom.in());
    }).mousedown(function(e){
      if (3 == e.which) {
        areaObj.css('zoom', Zoom.max());
      }
    }).bind("contextmenu", function(){
      return false;
    });

    //缩小操作空间
    var outAreaBtn = $('.outAreaBtn');
    outAreaBtn.click(function(){
      areaObj.css('zoom', Zoom.out());
    }).mousedown(function(e){
      if (3 == e.which) {
        areaObj.css('zoom', Zoom.min());
      }
    }).bind("contextmenu", function(){
      return false;
    });

    //倍率放大逻辑
    var Zoom = (function(prevBtnObj){
      var maxZoom = 2, minZoom = .1,
        zoom = 1, cancelBtn = null;
      function toZoom (type) {
        if (type === true) {
          zoom += .1;
        } else if (type === false) {
          zoom -= .1;
        } else {
          zoom = type
        }
        if (zoom > maxZoom) {
          zoom = maxZoom;
        } else if (zoom < minZoom) {
          zoom = minZoom;
        }
        toggleCancelBtn(zoom != 1);
        return zoom;
      };
      function toggleCancelBtn (type) {
        if (!cancelBtn) {
          cancelBtn = $(doc.createElement('span'));
          cancelBtn.addClass('pre-c1');
          cancelBtn.html('<img class="cancelZoomBtn" src="img/cexiao.png">');
        }
        if (type) {
          if (prevBtnObj.parent().find(cancelBtn).length == 0) {
            prevBtnObj.after(cancelBtn);
            cancelBtn.find('img').click(function(){
              toZoom(1);
            });
          }
        } else {
          cancelBtn.remove();
          areaObj.css('zoom', zoom);
        }
      };
      return {
        in: function(){ return toZoom(true) },
        out: function(){ return toZoom(false) },
        max: function(){ return toZoom(maxZoom) },
        min: function(){ return toZoom(minZoom) },
      };
    }(outAreaBtn.parent()));

    //鼠标位置记录
    var areaOffset = areaObj.offset();
    areaObj.mousemove(function(evt){
      var xy = getCoordinateByEvent(evt);
      $('.ip-coordinates').text(' x: '+ xy[0] +' y: '+ xy[1]);
    });
    function getCoordinateByEvent (evt) {
      //new goog.math.Coordinate();
      return [evt.pageX - areaOffset.left, evt.pageY - areaOffset.top];
    };

    //上传操作功能
    (function(){
      var upload_type = null;
      var uploadCore = new UploadsCore({
          debug: 1,
          inputId: 'uploadcore-input',
          fileType: ['image'],
          uploadURL: '/upload_file/',
          fileSuffix: {'image':['png', 'jpg', 'jpeg']},
          initpostBeforeCallback: function (file) {
            //初始化上传前回调
            return {
              postData: {
                upload_type: upload_type,
                file_name: file.name,
                file_type: file.type,
              }
            };
          },
          getMd5ingCallback: function (file, loaded, total) {
            //获取md5中回调
          },
          waitingCallback: function (data) {
            //等待上传中回调
          },
          startingCallback: function (data) {
            //开始上传中回调
          },
          progressCallback: function (data) {
            //上传传输中回调
          },
          successCallback: function (data) {
            //上传成功后回调
            data = data.response;
            switch (data.upload_type) {
              case 'background':
                /*createBackground(data.url);*/ break;
              case 'human':
                /*createHuman(data.url);*/ break;
              default:
                return TOOL.errorMsg($.i18n.prop('js_upload_error_tip'));
            }
            TOOL.successMsg($.i18n.prop('js_upload_success'));
          },
          failCallback: function (data) {
            //上传失败后回调
            TOOL.errorMsg($.i18n.prop('js_upload_failure_tip'));
          },
          endedCallback: function (data) {
            //结束上传后回调
          },
          errorCallback: function (data) {
            //失败后回调
          },
        }),
        input = $('#uploadcore-input');
      $('.myUploads').click(function(){
        var type = $(this).data('type');
        upload_type = type;
        input.click();
      }).css({
        cursor: 'pointer',
      });
    }());

    //读取列表功能
    (function(){
      var dir = '/blockly/apps/blocklyduino/img/';
      $('.openLibrary').click(function(){
        var type = $(this).data('type'),
          path = dir + type + '/';
        switch (type) {
          case 'background': break;
          case 'human': break;
          default: return TOOL.errorMsg($.i18n.prop('js_read_filelist_error'));
        }
        $.ajax({
          url:  path,
          success: function(data){
            var obj = $(doc.createElement('div'));
            obj.html(data);
            obj = obj.html(obj.find('ul'));
            layer.open({
              type: 1,
              shadeClose: true,
              area: ['465px', '380px'], //宽高
              content: obj.html(),
              title: $.i18n.prop('js_select')+' ' + (type=='background' ? $.i18n.prop('background') : $.i18n.prop('figure')),
              success: function(layero, index){
                switch (type) {
                  case 'background':
                    var callback = 'createBackground'; break;
                  case 'human':
                    var callback = 'createHuman'; break;
                }
                layero.find('ul').attr('id', 'images-list');
                layero.find('li>a').each(function(){
                  var src = path + $(this).attr('href');
                  $(this).attr('href', 'javascript:'+ callback +'(\''+ src +'\');layer.close('+ index +');');
                  $(this).html('').css({
                    backgroundImage: 'url('+src+')',
                  });
                });
              },
              end: function(layero){
                switch (type) {
                  case 'background':
                    var obj = bgContainer; break;
                  case 'human':
                    var obj = hmContainer; break;
                }
                obj.animate({
                  // scrollTop: obj[0].scrollHeight,
                }, 300);
              },
            });
          },
          error: function(){
            TOOL.errorMsg($.i18n.prop('js_read_filelist_error'));
          },
        });
      }).css({
        cursor: 'pointer',
      });
    }());

    //创建背景
    W.createBackground = function (url) {
      if (hasBgid(url)) {
        return false;
      }
      var obj = $(doc.createElement('div'));
      obj.addClass('bgk');
      obj.html('<img src="'+ url +'">');
      bgContainer.append(obj);
      setImageId(obj.find('img'));
      return obj;
    };

    //创建人物
    W.createHuman = function (url) {
      if (hasHmid(url)) {
        return false;
      }
      var obj = $(doc.createElement('div'));
      obj.addClass('change-img');
      obj.html('<img src="'+ url +'">');
      hmContainer.append(obj);
      setImageId(obj.find('img'));
      ActionBlock.Images.set(url);
      return obj;
    };

    //创建图片唯一Id
    function getImageId (src) {
      return SparkMD5.hash(src.split('/').pop());
    };
    function setImageId (obj) {
      obj = $(obj);
      obj.attr('data-id', getImageId(obj.attr('src')));
    };
    function hasHmid (src) {
      var nowId = getImageId(src);
      return hmContainer.find('img[data-id="'+ nowId +'"]').length > 0;
    };
    function hasBgid (src) {
      var nowId = getImageId(src);
      return bgContainer.find('img[data-id="'+ nowId +'"]').length > 0;
    };

    //获取保存配置
    W.getSaveConfig = function (string) {
      var config = {
        backgrounds: getBackgroundImgsrc(),
        humans: getHumanImgsrc(),
        currentBg: areaObj.data('bgSrc'),
        currentHm: ActionBlock.elementObj.find('img').attr('src'),
      };
      return string ? TOOL.jsonStrify(config) : config;
    };
    function getHumanImgsrc () {
      var humans = [];
      hmContainer.find('img').each(function(){
        humans.push($(this).attr('src'));
      });
      return humans;
    };
    function getBackgroundImgsrc () {
      var backgrounds = [];
      bgContainer.find('img').each(function(){
        if ($(this).parent().data('clear')) {
          return true;
        }
        backgrounds.push($(this).attr('src'));
      });
      return backgrounds;
    };

    //使用配置进行初始化
    W.initByConfig = function (config, string) {
      if (string) {
        config = TOOL.jsonParse(config);
      }
      config = config || {};
      initHumanImage(config.humans);
      initBackgroundImage(config.backgrounds);
      setTimeout(function(){
        initCurrentHm(config.currentHm);
        initCurrentBg(config.currentBg);
      }, 100);
    };
    function initHumanImage (humans) {
      hmContainer.find('img').not('[data-init="true"]').parent().remove();
      $.each(humans, function(key, src){
        var obj = createHuman(src);
        if (obj) {
          obj.find('img').on('error', function(){
            if (ActionBlock.elementObj.find('img').attr('src') == $(this).attr('src')) {
              hmContainer.find('img[data-init]').first().click();
            }
            obj.remove();
          });
        }
      });
    };
    function initBackgroundImage (backgrounds) {
      bgContainer.find('img').not('[data-init="true"]').parent().remove();
      $.each(backgrounds, function(key, src){
        var obj = createBackground(src);
        if (obj) {
          obj.find('img').on('error', function(){
            obj.remove();
          });
        }
      });
    };
    function initCurrentHm (hm) {
      if (!hm) {
        return false;
      }
      hm = getImageId(hm);
      hmContainer.find('img[data-id="'+ hm +'"]').click()
    };
    function initCurrentBg (bg) {
      if (!bg) {
        return false;
      }
      bg = getImageId(bg);
      bgContainer.find('img[data-id="'+ bg +'"]').click();
    };

    //放大|缩小操作区域
    var maxSpaceWin = null;
    $('.pre-img-head .icon-1 img').click(function(){
      if ($(this).data('ismax')) {
        layer.close(maxSpaceWin);
      } else {
        openMaxSpace($(this));
      }
    });
    function openMaxSpace (btn) {
      maxSpaceWin = layer.open({
        type: 1,
        shade: true,
        shadeClose: true,
        closeBtn: 0,  //不显示关闭按钮
        title: false, //不显示标题
        content: $('.pre-img-block'),
        success: function(layero, index){
          btn.data('ismax', true).attr('src', './img/suoxiao.png');
          layero.css({
            width: '90%',
            height: '80%',
          }).find('.layui-layer-content').css({
            height: '100%',
          });
          $(window).resize();
        },
        end: function(){
          btn.data('ismax', null).attr('src', './img/fangda.png');
        },
      });
    };

    $("#character_reset").click(function(){
      var blockly_stop = new WebSocket("ws:/"+bockly_ip+":"+bockly_port+"/stop_running");
      blockly_stop.onopen = function(evt) {  //绑定连接事件
        console.log("stop running Connection open........");
        blockly_stop.send("stop")
      };
      blockly_stop.onmessage = function(evt){
        if(evt.data=="ok"){
          blockly_stop.close()
        }

      };
      blockly_stop.onclose = function(evt) { //绑定关闭或断开连接事件
        console.log("stop running Connection closed.");
        ActionBlock.isAction();
        ActionBlock.reset();
        window.online_data_obj.clear_pin_value();
        // ActionBlock.exe_bock_not_reply({"method": "rest_board", "params": ['null']});
        window.blockly_is_run=false;
        var led_single=document.getElementsByClassName('led-single')[0];
        var led_four=document.getElementsByClassName('led-four');
        led_single.style.display="none";
        for(var i=0;i<led_four.length;i++){
          led_four[i].style.display="none";
        }
        var fater_node=led_single.parentNode;
        fater_node.style.display="none";
      };


    });

    function get_blockly_python(){
      /*获取积木的python代码，返回一个代码块*/
      var python_text=Blockly.Python.workspaceToCode(Blockly.mainWorkspace);
      console.log(python_text);
      return python_text;
    }

    var check_queue_timer=null;
    window.check_queue=function () {  //检测积木的执行队列是否有item
      var fulfil=ActionBlock.Queue.hasItem();
      if(fulfil){
      }else{
        clearInterval(check_queue_timer);
        window.blockly_is_run=false;   //是否在运行积木的状态
        $('.character_start').find('img').attr('src','img/run_blockly_dark.png');
      }
    }

    $(".character_start").click(function(){

      if(window.blockly_is_run==true){
        alert($.i18n.prop('js_online_running'));
        return;
      }
      var character_motion=get_blockly_python();
      upload_online_run_xml();
      try{
        $('.character_start').find('img').attr('src','img/run_blockly_bright.png');
        window.blockly_is_run=true;

        window.figure_ws = new WebSocket("ws://"+bockly_ip+":"+bockly_port+"/figure_state");
        window.figure_ws.onopen = function(evt) {
          window.figure_ws.send(JSON.stringify(ActionBlock.getInfo()))
        };
        window.figure_ws.onmessage=function (ev) {

        };
        window.figure_ws.onclose = function(evt){
          console.log("figure_ws close")
        };


        window.blockly_ws = new WebSocket("ws://"+bockly_ip+":"+bockly_port+"/run_code");

        window.blockly_ws.onopen = function(evt) {  //绑定连接事件
          console.log("run_code Connection open ...");
          window.blockly_ws.send(character_motion);
        };

        window.blockly_ws.onmessage = function(evt) {//绑定收到消息事件
          console.log( "Received Message: " + evt.data);

          var call_data=JSON.parse(evt.data);
          var callback_func=call_data["method"];
          var callbacl_arg=call_data["params"];
          if(callback_func=="set_panel_write_data"){
            ActionBlock.set_panel_write_data(callbacl_arg[0],callbacl_arg[1],0)
          }else if(callback_func=="set_panel_read_data"){
            ActionBlock.set_panel_read_data(callbacl_arg[0],callbacl_arg[1],0)
          }else if(callback_func=="exe_single_led_block"){
            ActionBlock.exe_single_led_block(callbacl_arg[0],callbacl_arg[1],callbacl_arg[2],0)
          }else if(callback_func=="exe_four_led_block"){
            ActionBlock.exe_four_led_block(callbacl_arg[0],callbacl_arg[1],callbacl_arg[2],callbacl_arg[3],0)
          }else if(callback_func=="move"){
            ActionBlock.move(-callbacl_arg[0],callbacl_arg[1])
          }else if(callback_func=="moveTo"){
            var x=callbacl_arg[0];
            var y=callbacl_arg[1];
            if (x=="NaN"){
              x=NaN
            }
            if(y=="NaN"){
              y=NaN
            }
            ActionBlock.moveTo(callbacl_arg[0],callbacl_arg[1],callbacl_arg[2])
          }else if(callback_func=="rotate"){
            ActionBlock.rotate(callbacl_arg[0],callbacl_arg[1])
          }else if(callback_func=="rotateTo"){
            ActionBlock.rotateTo(callbacl_arg[0],callbacl_arg[1])
          }
          else if(callback_func=="close_ws"){
            window.blockly_ws.close();
          }
          else if(callback_func=="ws_error_tip"){
            alert($.i18n.prop(callbacl_arg[0]));
          }

        };

        window.blockly_ws.onclose = function(evt) { //绑定关闭或断开连接事件
          console.log("run_code Connection closed.");
          check_queue_timer=window.setInterval("check_queue()",1000);
        };

      }
      catch (e){
        window.blockly_is_run=false;
        $('.character_start').find('img').attr('src','img/run_blockly_dark.png');
        alert($.i18n.prop('js_online_run_error')+e);
      }
      // check_queue_timer=window.setInterval("check_queue()",1000);

    });

  }(
    $('#operating-space'),  //操作空间
    $('.hm-container'),     //人物容器
    $('.bg-container'),     //背景容器
    document, window
  ));

  $('.attobut input').click(function(){
    $(this).parent().parent().parent().hide();
    var agree=$(this).attr("agree");
    $.ajax({
      url: "http://"+window.location.host+"/post_agree_state/",
      type: "Post",
      async: false,
      data:agree,
      dataType: "text",
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        alert("error!" + errorThrown);
      },
      success: function (data) {
        $(".attorney").hide();
      }
    });

  });
</script>
<script>
  function select_language(ele) {
    var language=$(ele).attr('value');
    $.ajax({
      url: "http://"+window.location.host+"/post_choose_language/",
      type: "Post",
      async: false,
      data:language,
      dataType: "text",
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        alert("error!" + errorThrown);
      },
      success: function (data) {
        new QWebChannel(qt.webChannelTransport, function (channel) {
          window.handler = channel.objects.handler;
          window.handler.choose_language(language);
        });
        location.href='/';
      }
    });
  }
</script>
</body>
</html>
